<template>
  <div>
    <el-form :model="form" :rules="rules" ref="form" label-width="70px">
      <el-form-item label="标题" prop="title">
        <el-input v-model="form.title"></el-input>
      </el-form-item>

      <el-form-item label="内容" prop="content">
        <el-input type="textarea" v-model="form.content" :rows="14"></el-input>
      </el-form-item>

      <el-form-item label="接收人" prop="receiver">
        <el-input v-model="form.receiver" style="width: 200px"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="submitForm">发送</el-button>
        <el-button @click="resetForm">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { xiaoxifasong } from "@/apis/lihan/Index.js";
export default {
  data() {
    return {
      time: +new Date(),
      form: {
        title: "",
        content: "",
        receiver: "",
      },
      rules: {
        title: [{ required: true, message: "请输入标题", trigger: "blur" }],
        content: [{ required: true, message: "请输入内容", trigger: "blur" }],
        receiver: [
          { required: true, message: "请输入接收人", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    submitForm() {
      // 发送
      // this.form.title=
      xiaoxifasong(
        this.form.title,
        this.form.content,
        this.form.receiver,
        this.time
      ).then((ok) => {
        console.log(ok);
      });
      this.$router.replace("/xiaoxi");
      console.log(this.$refs.form.value);
      this.$refs.form.validate((valid) => {
        if (valid) {
          // 发送消息的请求
          this.$message.success("发送成功");
        } else {
          return false;
        }
      });
    },
    resetForm() {
      this.$refs.form.resetFields();
    },
  },
};
</script>

<style scoped>
</style>